//# sourceURL=http://uMapApp/UI/Panel/Item/CountItem
define([
    "mhjs/mhjs"
], function (
    mhjs
) {

    function CountItem(option) {

        var _this = this;
        _this.isOpened = false;

        _this.ui = _this.ui || {};
        _this.ui.title = new mhjs.Div({"class": "title"});
        _this.ui.icon = new mhjs.Img({"class": "icon"});
        _this.ui.unit = new mhjs.Div({"class": "unit"});
        _this.ui.count = new mhjs.Div({"class": "count"});


        mhjs.Div.call(_this, option);
        _this.addClass("countItem");

        _this
            .append(_this.ui.icon)
            .append(_this.ui.title)
            .append(_this.ui.count)
            .append(_this.ui.unit)
        ;

    }

    var _class = CountItem;
    mhjs.Inherit(_class, mhjs.Div);


    Object.defineProperties(_class.prototype, {
        "title" : {
            set: function (title) {
                var _this = this;
                _this._title = title;
                _this.ui.title.text(title);
            },
            get: function () {
                return this._title;
            }
        },
        "count" : {
            set: function (count) {
                var _this = this;
                _this._count = count;
                _this.ui.count.text(count);
            },
            get: function () {
                return this._count;
            }
        },
        "icon"  : {
            set: function (icon) {
                var _this = this;
                _this._icon = icon;
                _this.ui.icon.attr("src", icon);
            },
            get: function () {
                return this._icon;
            }
        },
        "unit"  : {
            set: function (unit) {
                var _this = this;
                _this._unit = unit;
                _this.ui.unit.text(unit);
            },
            get: function () {
                return this._unit;
            }
        },
        "active": {
            value: function (isActive) {
                var _this = this;

                isActive = (isActive === undefined) || Boolean(isActive);
                _this.isActive = _this.isActive === undefined ? false : _this.isActive;

                if (isActive !== _this.isActive) {

                    if (isActive) {

                        if (_this.list && _this.list.length > 0) {
                            $.each(_this.list, function (i, item) {
                                item.open && item.open();
                            });

                        }

                        _this.addClass("active");
                        _this.trigger("active");
                    } else {

                        if (_this.list && _this.list.length > 0) {
                            $.each(_this.list, function (i, item) {
                                item.close && item.close();
                            });
                        }

                        _this.removeClass("active");
                        _this.trigger("unActive");
                    }

                    _this.isActive = isActive;

                }

            }
        }

    });

    return _class;

});